<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* unicode2iso plugin for CodeIgniter applications
* @author : Samuel Sanchez, http://www.kromack.com/, April 2009
* @link :
* @license : free
*/


    /**
     * Take an UTF8 string, and return an ISO-8859-1 string with all HTML special chars encoded exept those defined in the $retrieve array.
     *
     * @param string $str
     * @return string
     */
    function unicode2iso($str) {
        
        //Define HTML elements to retrive after conversion
        $retrieve = array('<br>', '<br />', '<br/>', '<u>',    '</u>', '<i>', '</i>', '<b>', '</b>');
        
        //HTML special chars conversion
        $str = htmlentities($str, ENT_QUOTES, 'UTF-8');
        
        //ISO-8859-1 conversion
        $str = utf8_decode($str);
        
        //Now, we resore our HTML elements
        foreach($retrieve as $row) {
            $str = str_replace(htmlentities($row, ENT_QUOTES), $row, $str);
        }
        
        return $str;        
    }

?>